// TOWN SCRIPT
//    Town 4: Guarded Tower

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	set_state_continue(26);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	if (get_flag(4,9) == 250)
	end();
	
	else set_state_continue(11);
break;

beginstate 11;
	if (character_in_party(328) > 3)
		set_state_continue(12);
	set_state_continue(15);
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0,"Searching behind the pillar, you find a concealed weapon: a special longsword usable only by the Seawyrm. It's definitely been here for a while, but still very usable. Seeing the sword, Shaw speaks up.",0);
	add_dialog_str(1,"_Battle soon should come. I now have no special weapon. You can, if..._ A pause. _I will can prepare, and but only if you give this._",0);
	add_dialog_str(2,"Do you give the sword to him, or keep it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Give.");
	add_dialog_choice(2,"Refuse.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(16);
	if (choice == 3)
		set_state_continue(14);
break;

beginstate 14;
	set_flag(4,0,1);
	set_terrain(25,21,0);
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0,"Searching behind the pillar, you find a concealed weapon: an iron longsword. It's definitely been here for a while, but still very usable.",0);
	add_dialog_str(1,"Do you take it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Take.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(13);
break;

beginstate 16;
	message_dialog("He nods and takes the blade.","");
	set_flag(4,1,1);
	set_state_continue(14);
break;

beginstate 17;
	message_dialog("The stairway has been blocked from beneath.","");
break;

beginstate 18;
	if (get_flag(4,9) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"You emerge from the tower. Not too much to your surprise, you see Aeschere a small distance away. Between, however, stand a band of well-armed soldiers in battle formation. Evidently, they've been waiting for you.",0);
	add_dialog_str(1,"_I am sorry, but I have other matters to attend to for now, and cannot stay to watch these... developments,_ Aeschere says, smiling ruefully. _Either you shall visit me again, or I you - but that comes later. Good day._",0);
	add_dialog_str(2,"He departs to the west, leaving the soldiers to face you.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(4,9,250);
	set_state_continue(19);
break;

beginstate 19;
	activate_hidden_group(1);
	set_state_continue(20);
break;

beginstate 20;
	if (get_flag(4,1) >= 1)
		set_state_continue(21);
	set_state_continue(25);
break;

beginstate 21;
	message_dialog("With a shout, Shaw leaps out, and in less than a second is past the soldiers' front line. Sword brandished, he engages the enemies in the back.",
	  "[An NPC has left your party.]");
		activate_hidden_group(2);
	  	set_state_continue(23);
break;

beginstate 22;
	message_dialog("You realize that Shaw is no longer with you. He must have somehow slipped away and escaped.",
	  "[An NPC has left your party.]");
	set_state_continue(23);
break;

beginstate 23;
	remove_char_from_party(328);
	set_state_continue(24);
break;

beginstate 24;
	set_town_visibility(4,1);
break;

beginstate 25;
	if (character_in_party(328) > 3)
		set_state_continue(22);
	set_state_continue(24);
break;

beginstate 26;
	if (get_flag(4,9) == 250)
	set_terrain(25,21,0);
break;

beginstate 27;
	out_move_party(43,23);
break;

beginstate 28;
	out_move_party(46,25);
break;

beginstate 29;
	out_move_party(43,27);
break;

beginstate 30;
	out_move_party(41,25);
break;
